package com.nhjf.dao.teachers;

import org.hibernate.Criteria;
import org.hibernate.FetchMode;
import org.hibernate.criterion.Restrictions;
import org.springframework.stereotype.Repository;

import com.nhjf.dao.BaseDao;
import com.nhjf.model.teachers.ArtPicturesCollection;
import com.nhjf.pojo.qo.teachers.ArtPicturesCollectionQo;
@Repository
public class ArtPicturesCollectionDao extends BaseDao<ArtPicturesCollection, ArtPicturesCollectionQo>{

	@Override
	protected Criteria buildCriteria(Criteria criteria, ArtPicturesCollectionQo qo) {
		// TODO Auto-generated method stub
		if(qo!=null) {
			criteria.setFetchMode("artPictures", qo.isSeachArtPictures()?FetchMode.JOIN:FetchMode.SELECT);	
			criteria.setFetchMode("user", qo.isSeachUser()?FetchMode.JOIN:FetchMode.SELECT);	
			if(qo.getArtPicturesId()!=null) {
				criteria.add(Restrictions.eq("artPictures.id",qo.getArtPicturesId()));
			}
			if(qo.getCollectionUserType()!=null) {
				criteria.add(Restrictions.eq("collectionUserType",qo.getCollectionUserType()));
			}
			if(qo.getUserId()!=null) {
				criteria.setFetchMode("user",FetchMode.SELECT);
				criteria.add(Restrictions.eq("user.id",qo.getUserId()));
			}
			if(qo.getCollectionTime()!=null) {
				criteria.add(Restrictions.eq("collectionTime",qo.getCollectionTime()));
			}
			if(qo.getArtPicturesCollectionId()!=null) {
				criteria.add(Restrictions.eq("id",qo.getArtPicturesCollectionId()));
			}

		}
		return criteria;
	}

	@Override
	protected Class<ArtPicturesCollection> getEntityClass() {
		// TODO Auto-generated method stub
		return ArtPicturesCollection.class;
	}

}
